package com.example.Laboratory.Controller;

import com.example.Laboratory.Entity.Contact;
import com.example.Laboratory.Service.ContactService;
import com.example.Laboratory.Untils.ResultCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;

@RestController
@Api(value = "Contact", description = "联系我们")
@RequestMapping(value = "/contact")
@CrossOrigin
public class ContactController {

    @Autowired
    ContactService contactService;

    @ApiOperation(value = "添加联系我们", notes = "添加联系我们")
    @RequestMapping(value = "/addContact", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
    public Object addContact (Contact t) throws IOException {
        return ResultCode.SUCCESS.result(contactService.addContact(t));
    }

    @ApiOperation(value = "删除联系我们", notes = "删除联系我们")
    @RequestMapping(value = "/deleteContact", method = RequestMethod.GET, produces = "application/json;charset=utf-8")
    public Object deleteContact (@RequestParam int contact_id) throws IOException {
        return ResultCode.SUCCESS.result(contactService.deleteContact(contact_id));
    }

    @ApiOperation(value = "查找联系我们", notes = "查找联系我们")
    @RequestMapping(value = "/researchContact", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
    public Object selectFriendship ( ) throws IOException {
        return ResultCode.SUCCESS.result(contactService.selectContact());
    }

    @ApiOperation(value = "修改联系我们", notes = "修改联系我们")
    @RequestMapping(value = "/reviseContact", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
    public Object updateContact (Contact i) throws IOException {
        return ResultCode.SUCCESS.result(contactService.updateContact(i));
    }
}
